﻿// ***********************************************************************
// Assembly         : INNOVACALL.Framework.Common
// Author           : LJO+01 (Laurent Jordi)
// Created          : 06-05-2013
// Last Modified By : LJO+01 (Laurent Jordi)
// Last Modified On : 06-05-2013
// ***********************************************************************
// <copyright file="_InnovacallExceptions_Base.cs" company="Copyright © Innovacall 2011">
//     Copyright (c) Copyright © Innovacall 2011. All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using INNOVACALL.Framework.Common.Logging;

//ToDo : LJO http://stackoverflow.com/questions/15167927/how-do-i-log-all-exceptions-globally-for-a-c-sharp-mvc4-webapi-app


namespace INNOVACALL.Framework.Common.InnovacallExceptions
{
    /// <summary>
    /// Enum enInnovacallExceptionTypes
    /// </summary>
    public enum enInnovacallExceptionTypes
    {
        /// <summary>
        /// The common exception
        /// </summary>
        CommonException,
        /// <summary>
        /// The data integrity exception
        /// </summary>
        DataIntegrityException,
        /// <summary>
        /// The friendly navigation exception
        /// </summary>
        FriendlyNavigationException,
        /// <summary>
        /// The identification exception
        /// </summary>
        IdentificationException,
        /// <summary>
        /// The innova tree exception
        /// </summary>
        InnovaTreeException,
        /// <summary>
        /// The initialization exception
        /// </summary>
        InitializationException,
        /// <summary>
        /// The initialization exception
        /// </summary>
        TypeParsingException
    }
    /// <summary>
    /// Class _InnovacallExceptions_Base
    /// </summary>
    public abstract class _InnovacallExceptions_Base : Exception, I_InnovacallExceptions_Base
    {
        /// <summary>
        /// Gets or sets the method.
        /// </summary>
        /// <value>The method.</value>
        public string Method { get; set; }
        /// <summary>
        /// Gets or sets the method parameters.
        /// </summary>
        /// <value>The method parameters.</value>
        public object MethodParameters { get; set; }
        /// <summary>
        /// Gets or sets the functional message.
        /// </summary>
        /// <value>The functional message.</value>
        public string FunctionalMessage { get; set; }
        /// <summary>
        /// Gets the type of the exception.
        /// </summary>
        /// <value>The type of the exception.</value>
        public enInnovacallExceptionTypes ExceptionType { get; private set; }
        /// <summary>
        /// Initializes a new instance of the <see cref="_InnovacallExceptions_Base"/> class.
        /// </summary>
        /// <param name="method">The method.</param>
        /// <param name="methodParameters">The method parameters.</param>
        /// <param name="functionalMessage">The functional message.</param>
        /// <param name="exceptionType">Type of the exception.</param>
        public _InnovacallExceptions_Base(string method, object methodParameters, string functionalMessage, enInnovacallExceptionTypes exceptionType)
        {
            this.ExceptionType = exceptionType;
            this.Method = method;
            this.MethodParameters = methodParameters;
            this.FunctionalMessage = functionalMessage;
        }

        /// <summary>
        /// Logs it as error
        /// </summary>
        public void LogIt()
        {
            Logger.Error(enLog.Error, this);
        }
        /// <summary>
        /// Logs it as specified
        /// </summary>
        public void LogIt(enLog logType)
        {
            switch (logType)
            {
                case enLog.Business:
                    Logger.Info(logType, this.FunctionalMessage);
                    break;
                default:
                    Logger.Error(logType, this);
                    break;
            }
        }
    }
}
